import { isAmumuComp, getAmumuCompInfo } from "../utils";
import { AMUMU_COMP_HIGHTLIGHT_CLASS } from "../constants/amumu";
import { showComponentInfo } from "./components/component-info/mount";

function attachPopoverListener(element) {
  let vm;
  $(element).mouseenter(
    () => {
      console.log("enter");
      vm = showComponentInfo(element);
    },
    () => {
      vm?.destory();
      console.log("leave");
    }
  );
}

function findComponents() {
  const elementList = [...document.querySelectorAll("[class^='mm']")];
  elementList.forEach(element => {
    if (isAmumuComp(element)) {
      attachPopoverListener(element);
      element.classList.add(AMUMU_COMP_HIGHTLIGHT_CLASS);
    }
  });
}

function loop() {
  findComponents();
}

setInterval(loop, 1000);
